package com.carlinfo.stu_ques.demo.dao.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;

import com.carlinfo.stu_ques.common.dao.impl.BaseDaoImpl;
import com.carlinfo.stu_ques.common.util.FileUtil;
import com.carlinfo.stu_ques.demo.dao.IDynastyDao;
import com.carlinfo.stu_ques.demo.pojo.Dynasty;

public class DynastyDaoImpl  extends BaseDaoImpl<Dynasty> implements IDynastyDao 
{
	
	/* 找一个容器;放的是朝代,实现CRUD
	 * Map:通过键快速的找到值
	 * 键是id(唯一标识),值:POJO;
	 *  */	
	private File dynastyFile = new File(this.parentFile,"dynasty.dat");
	
	/**
	 * id自加,这个id自加,只需要自己使用
	 */
	
	public DynastyDaoImpl()
	{
		readFile(dynastyFile);

	}
	
	@Override
	public int saveOneDao(Dynasty dynasty)
	{
		/* 就是为id赋值 */
		dynasty.setId(id);
		this.tempId = dynasty.getId();
		/* ID要不重复, */
		int resultId = super.saveOneDao(dynasty);
		writeFile(dynastyFile);
		return resultId ; 
	}

	@Override
	public void updateOneDao(Dynasty dynasty)
	{
		/* 如何换掉
		 * Map如何更新 */
		this.tempId = dynasty.getId();
		super.updateOneDao(dynasty);
		writeFile(dynastyFile);
	}

	@Override
	public void deleteOneDao(Dynasty dynasty)
	{
		/* 删除 */
		this.tempId = dynasty.getId();
		super.deleteOneDao(dynasty);
		writeFile(dynastyFile);
	}


	

	
	
}	
